package controllers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import models.AbstractActivity;
import models.IdeaRequest;
import models.InformationRequest;
import play.mvc.With;
import utils.Paginate;
import utils.json.data.ActivityJson;

@Check(Security.USER_ROLE)
@With(Secure.class)
public class UserController extends BaseController {
	
	public static void home() {
		render();
	}
	
	/**
	 * Renders a json list of the current information request. This is for the home page, the first column in the view.
	 */
	public static void openInformationRequest(Integer size, Integer page) {
		List<InformationRequest> infoRequest = InformationRequest.findAllOpen(getCurrentDate(), null);
		Paginate p = new Paginate<InformationRequest>(infoRequest, size);
		renderJSON(createJsonList(p.getPage(page)));
	}
	
	/**
	 * Renders a json list of the current ideas request. This is for the home page, the first column in the view.
	 */
	public static void openIdeaRequest(Integer size, Integer page) {
		List<IdeaRequest> ideaRequest = IdeaRequest.findAllOpen(getCurrentDate(), null);
		Paginate p = new Paginate<IdeaRequest>(ideaRequest, size);
		renderJSON(createJsonList(p.getPage(page)));
	}
	
	private static List<ActivityJson> createJsonList(List<? extends AbstractActivity> list) {
		List<ActivityJson> jsonList = new ArrayList<ActivityJson>();
		for(AbstractActivity info : list) {
			ActivityJson a = new ActivityJson(info);
			jsonList.add(a);
		}
		
		return jsonList;
	}
}
